const globalPackageConfig = require('./package-configs');

const packageConfig = {
  scripts: {},
  dependencies: {},
  devDependencies: {},
};

const addScripts = (script = {}) => {
  Object.assign(packageConfig.scripts, script);
};

const addDependencies = (dpd = {}) => {
  Object.assign(packageConfig.dependencies, dpd);
};

const addDevDependencies = (dpd = {}) => {
  Object.assign(
    packageConfig.devDependencies,
    dpd
  );
};

const genPackage = (api, options) => {
  addScripts(globalPackageConfig.base.scripts);
  addDependencies(
    globalPackageConfig.base.dependencies
  );
  addDevDependencies(
    globalPackageConfig.base.devDependencies
  );

  addScripts(globalPackageConfig.lowcode.scripts);
  addDependencies(
    globalPackageConfig.lowcode.dependencies
  );
  addDevDependencies(
    globalPackageConfig.lowcode.devDependencies
  );

  addDependencies({
    '@hips/plugin-vue-i18n': '^1.0.0',
  });

  addDevDependencies({ stylus: '^0.54.7' });
  addDevDependencies({
    'stylus-loader': '^3.0.2',
  });

  addDevDependencies({ less: '^3.10.3' });
  addDevDependencies({ 'less-loader': '^5.0.0' });

  api.extendPackage((pkg) => {
    return packageConfig;
  });
};

module.exports = genPackage;
